package com.base.common.enums;

/**
 * 返回结果状态码
 *
 * @author Pengyan
 * @date 2018/8/14 16:32
 **/
public enum ResultCodeEnum {

    SUCCESS(0, "请求成功"),
    BUSINESS_WARN(-1, "业务异常提示"),
    FAILURE(-2, "系统异常请求失败"),
    UNKNOWN_ERROR(-3, "未知错误"),
    TOKEN_ERROR(-4, "token过期");

    private int code;

    private String desc;

    ResultCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static ResultCodeEnum getResultCode(int code) {
        for (ResultCodeEnum resultCode : values()) {
            if (resultCode.getCode() == (code)) {
                return resultCode;
            }
        }
        return UNKNOWN_ERROR;
    }
}
